--- Compute and print the golden ratio
module examples.GoldenRatio where

import Data.List (dropUntil)

fibs = 1:1:zipWith (+) fibs (tail fibs) :: [Long]

infix 6 ***

(***) n  = packed . replicate n

main _ = do
    println ("The golden ratio is " ++ show golden 
             ++ " = (" ++ show nom ++ "/" ++ show denom ++ ")")
    -- print a 48x30 box of stars
    replicateM_ 30 (println ((30*golden).long.int *** '*'))    
  where
    golden = nom.double / denom.double
    (denom, nom) = head . dropUntil closeEnough . zip fibs $ (tail fibs)
    closeEnough (d,n) = abs (a-b) < 1.0e-9
        where
            b  = Long.double n / Long.double d
            a  = (1+b)/b 
    
